<?php

/**
 * Class for viewing a CSS declaration.
 * The properties and values are respectively the keys and values of an associative array.
 *
 * @author Ian Clarence ian.clarence@gmail.com
 */ 
class ViewDeclaration extends Component {

    /**
     * The constructor.
     *
     * @param array $fields
     */
    public function __construct(array $fields = array()) {        
        parent::__construct($fields);
    }
    
    /**
     * Adding a property to the declaration.
     * 
     * @param string $property
     * @param string $value 
     */
    public function addProperty($property, $value) {
        $this->fields[$property] = $value;
    }
    
    /**
     * Viewing the formatted declaration.
     *
     * @return string
     */    
    public function view() {
        if (count($this->fields) == 0) {
            return '';
        }
        $output = '{' . "\n";
        foreach ($this->fields as $fieldKey => $field) {
            $output .= ViewHtmlElement::TAB_STRING . $fieldKey . ': ' . $field . ';' . "\n";
        }
        $output .= '}' . "\n";
        return $output;
    }
    
}